<?php defined('SYSPATH') OR die('No direct access allowed.');

class Song_Hits_Controller extends Master_Search_Controller 
{
		
	public function index()
	{
		$view = new View('search/song_hits');

		$auth = new Auth();
		if ($auth->logged_in('admin')) {
			$this->set_title('ผู้ดูแลระบบ - ค้นหาด้วยชื่อเพลงฮิต');
		} 
		else if ($auth->logged_in()) {
			$this->set_title('สมาชิก - ค้นหาด้วยชื่อเพลงฮิต');	
		}
		else {
			$this->set_title('ค้นหาด้วยชื่อเพลงฮิต');	
		}
		
		$form = array(
			'profile_id' => '',
			'txtCriteria' => '',
			'rdoCategory' => '1',
		);
		
		$view->form = $form;
		$view->pagination = '';
    	$this->template->content = $view;
		$this->template->render(TRUE);
	}
	
	public function page($query='', $order='1', $pagenum=1)
    {
		$view = new View('search/song_hits');

        $searchs = new Searchs_Model;
        $searchs->set_song_hits_criteria($query);

        // Instantiate Pagination, passing it the total number of product rows.
        $paging = new Pagination(array
		(
			'base_url'    => 'search/song_hits/page/' . urlencode($query) . '/' . $order . '/',
			'uri_segment' => 6,
			'total_items' => $searchs->count_search_by_songs_hits($order),
		));

        // Render the page links
        $view->pagination = $paging->render();

        // Display X items per page, from offset = page number
        $view->result = $searchs->browse_search_by_songs_hits($paging->items_per_page, $paging->sql_offset, $order);

        $form = array(
			'profile_id' => '',
			'txtCriteria' => $query,
			'rdoCategory' => $order,
		);
        
    	$auth = new Auth();
		if ($auth->logged_in('admin')) {
			
			$form['profile_id'] = $auth->get_user()->id;
			$this->set_title('ผู้ดูแลระบบ - ค้นหาด้วยชื่อเพลงฮิต');
		} 
		else if ($auth->logged_in()) {
			$form['profile_id'] = $auth->get_user()->id;
			$this->set_title('สมาชิก - ค้นหาด้วยชื่อเพลงฮิต');	
		}
		else {
			$this->set_title('ค้นหาด้วยชื่อเพลงฮิต');	
		}
		
    	$view->form = $form;
    	$this->template->content = $view;
		$this->template->render(TRUE);
    }
}
